package com.ruoyi.project.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.mapper.SysDogOrderMapper;
import com.ruoyi.project.system.domain.SysDogOrder;
import com.ruoyi.project.system.service.ISysDogOrderService;

/**
 * 电子狗订单Service业务层处理
 *
 * @author ruoyi
 * @date 2020-08-04
 */
@Service
public class SysDogOrderServiceImpl implements ISysDogOrderService
{
    @Autowired
    private SysDogOrderMapper sysDogOrderMapper;

    /**
     * 查询电子狗订单
     *
     * @param orderId 电子狗订单ID
     * @return 电子狗订单
     */
    @Override
    public SysDogOrder selectSysDogOrderById(Long orderId)
    {
        return sysDogOrderMapper.selectSysDogOrderById(orderId);
    }

    /**
     * 查询电子狗订单列表
     *
     * @param sysDogOrder 电子狗订单
     * @return 电子狗订单
     */
    @Override
    public List<SysDogOrder> selectSysDogOrderList(SysDogOrder sysDogOrder) {
//        List<SysDogOrder> sysDogOrders = new ArrayList<>();
//        List<SysDogOrder> orderLists = sysDogOrderMapper.selectSysDogOrderList(sysDogOrder);
//        if (orderLists.size() > 0) {
//            for (int i = 0; i < orderLists.size(); i++) {
//                SysDogOrder order = new SysDogOrder();
//                BeanUtils.copyProperties(order, orderLists.get(i));
//                Long price = order.getDogNowPrice() + order.getDogNowPrice() * order.getDogRate() / 100;
//                System.out.println("price = " + price);
//                if (price < order.getDogPriceUp()) {
//                    order.setDogIsFenlie(0L);
//                } else {
//                    order.setDogIsFenlie(1L);
//                }
//                sysDogOrders.add(order);
//            }
//        }
//
//        return sysDogOrders;
        return sysDogOrderMapper.selectSysDogOrderList(sysDogOrder);
    }

    /**
     * 新增电子狗订单
     *
     * @param sysDogOrder 电子狗订单
     * @return 结果
     */
    @Override
    public int insertSysDogOrder(SysDogOrder sysDogOrder)
    {
        sysDogOrder.setCreateTime(DateUtils.getNowDate());
        return sysDogOrderMapper.insertSysDogOrder(sysDogOrder);
    }

    /**
     * 修改电子狗订单
     *
     * @param sysDogOrder 电子狗订单
     * @return 结果
     */
    @Override
    public int updateSysDogOrder(SysDogOrder sysDogOrder)
    {
        sysDogOrder.setUpdateTime(DateUtils.getNowDate());
        return sysDogOrderMapper.updateSysDogOrder(sysDogOrder);
    }

    /**
     * 批量删除电子狗订单
     *
     * @param orderIds 需要删除的电子狗订单ID
     * @return 结果
     */
    @Override
    public int deleteSysDogOrderByIds(Long[] orderIds)
    {
        return sysDogOrderMapper.deleteSysDogOrderByIds(orderIds);
    }

    /**
     * 删除电子狗订单信息
     *
     * @param orderId 电子狗订单ID
     * @return 结果
     */
    @Override
    public int deleteSysDogOrderById(Long orderId)
    {
        return sysDogOrderMapper.deleteSysDogOrderById(orderId);
    }
}
